package com.game;

import android.content.Context;
import android.graphics.*;
import android.graphics.BitmapFactory;
import android.view.Display;
import android.view.WindowManager;
import android.widget.*;

public class PongBall extends Pongitem {
	
	

	


	public PongBall(Context context, int X, int Y){
		BitmapFactory.Options fact = new BitmapFactory.Options();
		fact.inJustDecodeBounds = true;
		id = countBalls;
		countBalls++;
		VX = 5;
		VY = 20;	
		WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		Display display = win.getDefaultDisplay();
		width = display.getWidth();
		height = display.getHeight();
		this.X = width / 2;
		this.Y = height / 3;
	}
	

	





	public void onMove(int newX, int newY, Pongitem pb){
		
		
		int rectX1 = pb.getX();
		int rectX2 = rectX1 + 150 - 1;
		int rectY1 = pb.getY();
		int rectY2 = rectY1 + 40 - 1;
		
		if(X >= rectX1
		&& Y <= rectY2
		&& X <= rectX2
		&& Y >= rectY1){
			this.Y -= VY;
			this.X -= VX;
			VY = -VY;
		}
		
		if(X > width){
			homeActivity.score++;
			homeActivity.updateScore();
			this.Y -= VY;
			this.X -= VX;
			VX = -VX; 
		}
		
		if(Y > height){
			homeActivity.score++;
			homeActivity.updateScore();
			this.X -= VX;
			this.Y -= VY;
			
			VY= -VY;
		}
		
		if(X < 0){
			homeActivity.score++;
			homeActivity.updateScore();
			this.Y -= VY;
			this.X -= VX;
			VX = -VX;
		}
		
		if(Y < 20){
			homeActivity.score++;
			homeActivity.updateScore();
			this.X -= VX;
			this.Y -= VY;
			VY = -VY;
		}
		
		this.X += VX;
		this.Y += VY;
		
	}
}
